package jdklearning.sql;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author shenenlu 2021年07月05日 上午10:21:39
 */
public class JDBCConnectionAndQuery {


    private static void query() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection(
                    "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC",
                    "root", "root");
            PreparedStatement ps = conn.prepareStatement("select count(*) from person");
            ResultSet rs = ps.getResultSet();
            System.out.println(rs);
            boolean executeResult = ps.execute();
            System.out.println(executeResult);
            rs = ps.getResultSet();
            System.out.println(rs);
            rs.next();
            System.out.println(rs.getInt(1));
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        query();
    }


}
